
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="style_form.css" />
	<script language="javascript" src="error_valid.js"></script>
</head>

<?php
	
	// connect to the database
	 include('stdlib.php');
	 include('Connect_DB.php');
	 include('Model.php');

	 // check if the form has been submitted. If it has, start to process the form and save it to the database
	 if (isset($_POST['add']))
	 {  
		// get form data, making sure it is valid
		 $ma_ng = $_POST['ma_ng'];
		 $name = $_POST['name'];
		 $full_name = $_POST['full_name'];
		 $id_dv = $_POST['id_dv'];
		 
		 // check to make sure both fields are entered
		if ($ma_ng == '' || $name == '' || $full_name == '' || $id_dv == '' )
		{
			 //Dont submit
		}
		else
		{
			//Check "Ma Don Vi" On the form with "maDonvi" is Primary key of "donvi" table within Database
			 $row = Error_Add_Nganh($ma_ng); //Call function from file Moodel.php
			 if($row !=0)
			 	$error.= '"Mã Ngành" bạn nhập trên Form đã tồn tại trong CSDL.'; 
			else
			{
				Add_Nganh(); //Call function from file Model.php
				$message = 'Bạn đã thêm thông tin thành công'. ' Bạn Click<a href="View_View_Nganh.php" > Here </a> Để quay trở về trang View_View_Nganh.php';
				$ma_ng = $name = $full_name = $id_dv ='';
			}
		}
		
		//include('View_Action_Nganh.php');
		
	 }
						
	echo '<h2><center>THÊM THÔNG TIN NGÀNH ÐÀO TẠO</center></h2>';
	echo '<br /><hr>';
	
	include('Form_Add_Nganh.php');
	
	echo '<center><b><font color="red">'.$message.'</font></b></center>';
	echo '<center><b><font color="red">'.$error.'</font></b></center>';

?>